import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
// import remove from '@dfeidao/atom-web/local/remove';
import javadsd from '@dfeidao/atom-web/msg/javadsd';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
// import whoami from '@dfeidao/atom-web/msg/whoami';
import confirm, { ConfirmResult } from '@dfeidao/atom-web/msgbox/confirm';
import render from '@dfeidao/atom-web/render/render';

import error from '@dfeidao/atom-web/msgbox/error';
import success from '@dfeidao/atom-web/msgbox/success';
import P06 from './P06';

export default async function a012(fd: IFeidaoAiBrowserComponent) {
	// 保存
	const productid = get(fd, 'productid');
	const level_no = get(fd, 'level_no111');
	// debugger;
	const listt = fd.data.node.querySelectorAll<HTMLDivElement>('[draggable="true"]');
	const atomm = new Array();
	if (atomm.length > 0) {
		listt.forEach((i: HTMLElement) => {
			const level_no1 = i.getAttribute('level_no');
			const level_name1 = i.getAttribute('level_name');
			const order_num1 = i.getAttribute('order_num');
			atomm.push({ level_no: level_no1, level_name: level_name1, order_num: order_num1 });
		});
		await nodejs('level-inf/zj-000001/s006', { atomm });
	}
	if (!level_no) {
		error('请先选择等级');
		return;
	}
	const select = fd.data.node.querySelector<HTMLSelectElement>('[select]');
	const index = select.options.selectedIndex;
	const client_type1 = select.options[index].value;
	const a = get(fd, 'origin_obj') as Map<string, { left: {}, right: Array<{}> }>;
	// console.log(a.values());
	const newarr = Array.from(a.values());
	console.log(newarr);
	// return;
	const flag = await confirm('是否更新该等级下租户已分配的功能？', '提示', '确定', '取消', 'rgba(153, 153, 153, 1)');
	switch (flag) {
		case ConfirmResult.YES:
			// 确定
			const res1 = await nodejs('level-inf/zj-000001/s007', {
				productid, level_no, client_type: client_type1, newarr
			});
			const condition = {
				param: {
					level_no,
					productid
				}
			};
			if (res1 === 'success') {
				const ret = await javadsd('12', '12', 'levelformchangetenantform', condition);
				// debugger;

				window.console.log(res1, ret);

				success('成功');
				render(fd, '', P06, "P06", "inner");

				// remove(fd, 'level_no111');
			} else {
				error('失败');
			}
			break;
		case 'no':
		// 取消
	}
}
